package com.dao.impl;

import com.Bean.Employee;
import com.Bean.VoBean.SocialUser;
import com.dao.EmployeeDao;
import com.util.JdbcUtil;

import java.sql.SQLException;
import java.util.List;

public class EmployeeDaoimpl implements EmployeeDao {
    @Override
    public int insert(Employee employee) throws SQLException {
        return 0;
    }

    @Override
    public List<Employee> queryData(Employee employee) throws IllegalAccessException, SQLException, InstantiationException {
        return null;
    }

    @Override
    public int update(Employee employee) throws SQLException {
        return 0;
    }

    @Override
    public int deleteById(Object id) throws SQLException {
        return 0;
    }

    @Override
    public Employee login(String userName, String password) throws IllegalAccessException, SQLException, InstantiationException  {
        String sql=" SELECT * from  employee where ename=? and epwd=?";
        List<Employee> employees = JdbcUtil.queryData(sql, Employee.class,userName,password);
        if (employees!=null && employees.size()>0){
          return   employees.get(0);
        }
         return null;
    }

    @Override
    public Employee userLoginMobile(String phone) throws IllegalAccessException, SQLException, InstantiationException {
        String sql  ="select * from employee where ephone=?";
        List<Employee> employees = JdbcUtil.queryData(sql, Employee.class, phone);
        if (employees.size()>0){
            return employees.get(0);
        }
        return null;
    }

    @Override
    public Employee sociaUser(SocialUser socialUser) throws IllegalAccessException, SQLException, InstantiationException {
        return null;
    }

    @Override
    public Employee queryDataByUid(SocialUser socialUser) throws IllegalAccessException, SQLException, InstantiationException {
        String sql ="select * from employee where social_uid=?";
           List<Employee> employees = JdbcUtil.queryData(sql, Employee.class, socialUser.getUid());
        if (employees.size()>0){
            return employees.get(0);
        }
        return null;
    }

    @Override
    public int updateDataByid(Employee employee) throws IllegalAccessException, SQLException, InstantiationException {
        String sql="UPDATE employee set access_token=?,expires_in=? WHERE eid=?";
        return JdbcUtil.insertOrUpdateOrDelete(sql,new Object[]{employee.getAccess_token(),employee.getExpires_in(),employee.getEid()});
    }

    @Override
    public int insertSocialUser(Employee employee) throws IllegalAccessException, SQLException, InstantiationException {

        String sql="INSERT INTO employee(eid,`name`,social_uid,access_token,expires_in) VALUES(?,?,?,?,?)";
        return JdbcUtil.insertOrUpdateOrDelete(sql,new Object[]{employee.getEid(),employee.getName(),employee.getSocial_uid(),employee.getAccess_token(),employee.getExpires_in()});
    }
}
